package com.zzyl.mapper;


import com.github.pagehelper.Page;
import com.zzyl.dto.ProjectPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.entity.NursingPlanProject;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface NursingPlanMapper {

    /**
     * 获取所有护理计划
     *
     * @return
     */
    @Select("select * from nursing_plan")
    List<NursingPlanVo> getAllNursingPlan();

    /**
     * 根据id查询护理计划
     *
     * @param id
     * @return
     */
    @Select("select * from nursing_plan where id = #{id}")
    NursingPlanVo getNursingPlanById(Long id);


    /**
     * 根据根据计划id查询获取关联表信息及项目名称
     *
     * @param id
     * @return
     */

    List<ProjectPlanDto> getPlanProjects(Long palnId);


    /**
     * 修该护理计划表
     *
     * @param nursingPlan
     */
    @Update("update nursing_plan set plan_name=#{planName}," +
            "status=#{status}," +
            "update_time=#{updateTime}" +
            ",update_by=#{updateBy}" +
            " where id=#{id}")
    void updatePlan(NursingPlan nursingPlan);

    /**
     * 根据计划id删除计划、项目关联信息
     *
     * @param id
     */
    @Delete("delete  from nursing_plan_project where plan_id=#{id}")
    void deleteByPlanId(Long id);

    /**
     * 插入计划、项目关联信息
     *
     * @param nursingPlanProjectList
     */
    void insertNursingPlanProject(List<NursingPlanProject> nursingPlanProjectList);

    /**
     * 添加计划、项目关联信息
     *
     * @param nursingPlan
     */
    @Insert("insert into nursing_plan (plan_name,status,create_time,create_by)" +
            "values(#{planName},#{status},#{createTime},#{createBy})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void  addNursingPlan(NursingPlan nursingPlan);


    Page<NursingPlanVo> getNursingPlanByPage(String planName, Integer status);

    /**
     * 通过计划id删除计划
     *
     * @param id
     */
    @Delete("delete from nursing_plan where id=#{id}")
    void deleteById(Long id);

    /**
     * 根据id启用/禁用护理计划
     *
     * @param id
     * @param status
     * @param updateBy
     * @param updateTime
     */
    @Update("update  nursing_plan set status=#{status},update_by=#{updateBy},update_time=#{updateTime} where id=#{id}")
    void updateStatusById(Long id, Integer status, Long updateBy, LocalDateTime updateTime);
}
